Skip to content

Conversation

@weliveindetail
Copy link
Member

Pass plugins are a commonly requested extension for LLVM-based tools. Better support for these extensions benefits the LLVM ecosystem and might slow down the growth of the monorepo. We currently lack test coverage for pass plugins, because we only have example plugins (and no reference), but most bots don't build examples. As a result we also can't test cross-project integration. Features like parsing of plugin parameters in Clang remain broken and get no attention.

This draft adds a reference plugin in LLVM that we can test in subprojects. For illustration, it comes with tests for plugin parameters and pipeline entry-points.

weliveindetail and others added 4 commits July 31, 2025 15:16
Both internally and externally we instrument code all the time. Usually,
those are hand written traversals that look for some specific
instructions or program points and then provide information to a
runtime. Since the real difference is in the runtime, and the
instrumentation is basically always the same, people can use this
Instrumentor pass and configure it to their needs.

Initial implementation only instruments alloca instructions but shows
the setup, and configurability via a JSON file.
@weliveindetail
Copy link
Member Author

I guess we don't want another generic plugin like Bye? 👋 I integrated the Instrumentor pass from #119038

@github-actions
Copy link

github-actions bot commented Jul 31, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@@ -0,0 +1,341 @@
//===-- Instrumentor.cpp - Highly configurable instrumentation pass -------===//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the instrumentor - but is there a user that needs this today? I wonder if this should be part of a test or example instead of a full tool. For what it's worth, I would like some code that uses the plugin API to be built by default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need tool-like plugin to get test coverage for subprojects and packagers. I guess there are users, but I don't know for sure. It was presented on EuroLLVM with the idea to hardcode it as a default-disabled pass. I think it's a great fit for a plugin that lives upstream. @jdoerfert @kevinsala What do you think?

Comment on lines +21 to +26
static std::optional<std::string> getEnv(const std::string &Var) {
const char *Val = std::getenv(Var.c_str());
if (!Val)
return std::nullopt;
return std::string(Val);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are already using command-line options elsewhere in the instrumentation pass, why not use them here instead of environment variables?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the moment, I was aiming for minimal changes on the Instrumentor, so I kept it as a leftover from my previous draft that used a generic plugin. They define in which part(s) of the pass pipeline we insert the pass. In contrast to the current command-line options this is not specific for the Instrumentor. I am happy to change it to whatever fits best.

@ashermancinelli
Copy link
Contributor

Thank you for this! I would love to see a user of the plugin API built by default, both as extra assurance that the API maintained and to serve as documentation for plugin authors. I think this is valuable work.

Copy link
Member Author

@weliveindetail weliveindetail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback

@@ -0,0 +1,341 @@
//===-- Instrumentor.cpp - Highly configurable instrumentation pass -------===//
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need tool-like plugin to get test coverage for subprojects and packagers. I guess there are users, but I don't know for sure. It was presented on EuroLLVM with the idea to hardcode it as a default-disabled pass. I think it's a great fit for a plugin that lives upstream. @jdoerfert @kevinsala What do you think?

Comment on lines +21 to +26
static std::optional<std::string> getEnv(const std::string &Var) {
const char *Val = std::getenv(Var.c_str());
if (!Val)
return std::nullopt;
return std::string(Val);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the moment, I was aiming for minimal changes on the Instrumentor, so I kept it as a leftover from my previous draft that used a generic plugin. They define in which part(s) of the pass pipeline we insert the pass. In contrast to the current command-line options this is not specific for the Instrumentor. I am happy to change it to whatever fits best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants